package com.lkxicy.wos.mapper;

import com.lkxicy.wos.pojo.entity.Staff;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lkxicy
 * @since 2020-11-30
 */
public interface StaffMapper extends BaseMapper<Staff> {

    @Select("select * from staff where deleted=0 and staffNumber!='admin' and staffNumber!='superAdmin'")
    public List<Staff> findAllStaff();

    @Select("select * from staff where staffNumber=#{staffNumber}")
    public Staff findStaffByNumber(String staffNumber);

    @Update("update staff set password=#{password} where staffNumber=#{staffNumber}")
    public void changeStaffPassword(@Param("staffNumber") String staffNumber, @Param("password") String password);

    @Select("select * from staff where staffNumber=#{staffNumber} and password=#{password}")
    public Staff staffLogin(@Param("staffNumber") String staffNumber,@Param("password") String password);

    @Update("UPDATE staff\n" +
            "SET staffNumber=#{staffNumber},`name`=#{name},sex=#{sex}," +
            "department=#{department},phoneNumber=#{phoneNumber},email=#{email},salary=#{salary}\n" +
            "WHERE id=#{id}")
    public void changeStaff(@Param("staffNumber") String staffNumber,
                            @Param("name") String name,
                            @Param("department") String department,
                            @Param("phoneNumber") String phoneNumber,
                            @Param("sex") String sex,
                            @Param("email") String email,
                            @Param("salary") double salary,
                            @Param("id") int id);

    @Select("SELECT DISTINCT department FROM staff")
    public List<String> selectAllDepartment();

}
